package com.shensi.adminCollect.controller.fleet;

import com.shensi.adminCollect.common.constant.UserConstants;
import com.shensi.common.core.controller.BaseController;
import com.shensi.common.core.domain.AjaxResult;
import com.shensi.common.core.page.TableDataInfo;
import com.shensi.adminCollect.domain.fleet.dto.FleetCardRechargeRecordDto;
import com.shensi.adminCollect.domain.fleet.form.FleetCardQueryForm;
import com.shensi.adminCollect.domain.fleet.form.FleetCardRechargeRecordQueryForm;
import com.shensi.adminCollect.domain.fleet.vo.FleetCardRechargeRecordVo;
import com.shensi.adminCollect.domain.fleet.vo.FleetCardRecordBalanceVo;
import com.shensi.adminCollect.domain.fleet.vo.FleetCardVo;
import com.shensi.adminCollect.service.fleet.FleetCardRechargeRecordService;
import com.shensi.adminCollect.service.fleet.FleetCardService;
import com.shensi.adminCollect.domain.station.Station;
import com.shensi.adminCollect.service.station.IStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import com.shensi.common.core.domain.model.LoginUser;
import com.shensi.common.core.utils.SecurityUtils;
import com.shensi.common.core.domain.entity.SysUser;
@Api(tags = "车队卡充值记录管理")
@RestController
@RequestMapping("/fleetCard/recharge")
public class FleetCardRechargeRecordController extends BaseController {

    @Autowired
    private FleetCardRechargeRecordService fleetCardRechargeRecordService;

    @Autowired
    private FleetCardService fleetCardService;

    @Autowired
    private IStationService stationService;

    /**
     * 查询车队卡充值记录列表
     */
    @GetMapping("/page")
    @ApiOperation(value = "车队卡充值记录分页列表", notes = "车队卡充值记录分页列表")
    public TableDataInfo page(FleetCardRechargeRecordQueryForm fleetCardRechargeRecordQueryForm) {
        startPage();
        List<FleetCardRechargeRecordVo> list = fleetCardRechargeRecordService.selectFleetCardRechargeRecordList(fleetCardRechargeRecordQueryForm);
        return getDataTable(list);
    }

    /**
     * 余额明细
     * */
    @GetMapping("/cdk/balance")
    @ApiOperation(value = "车队卡余额明细",httpMethod = "GET")
    public TableDataInfo balanceDetails(FleetCardRechargeRecordDto fleetCardRechargeRecordDto){
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();

        if(UserConstants.LEVEL_TWO.equals(user.getUserLevel())){
            fleetCardRechargeRecordDto.setEnterpriseId(user.getEnterpriseId());
        }
        if(UserConstants.LEVEL_THREE.equals(user.getUserLevel())){
            fleetCardRechargeRecordDto.setStationId(user.getStationId());
        }

        startPage();
        List<FleetCardRecordBalanceVo> list = fleetCardRechargeRecordService.selectFleetCardRecordBalance(fleetCardRechargeRecordDto);
        return getDataTable(list);
    }

    /**
     * 余额明细统计
     * */
    @GetMapping("/balance/statistics")
    @ApiOperation(value = "余额明细统计",httpMethod = "GET")
    public AjaxResult balanceStatistics(FleetCardRechargeRecordDto fleetCardRechargeRecordDto){
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();

        if(UserConstants.LEVEL_TWO.equals(user.getUserLevel())){
            fleetCardRechargeRecordDto.setEnterpriseId(user.getEnterpriseId());
        }
        if(UserConstants.LEVEL_THREE.equals(user.getUserLevel())){
            fleetCardRechargeRecordDto.setStationId(user.getStationId());
        }
        FleetCardRecordBalanceVo fleetCardRecordBalanceVo = fleetCardRechargeRecordService.selectFleetCardRecordStatistics(fleetCardRechargeRecordDto);
        return AjaxResult.success(fleetCardRecordBalanceVo);
    }

    @GetMapping("/fleetName")
    @ApiOperation(value = "查询车队卡列表",httpMethod = "GET")
    public AjaxResult getFleetName(FleetCardQueryForm fleetCardQueryForm){

        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();

        if(UserConstants.LEVEL_TWO.equals(user.getUserLevel())){
            fleetCardQueryForm.setEnterpriseId(user.getEnterpriseId());
        }
        if(UserConstants.LEVEL_THREE.equals(user.getUserLevel())){
            Station station = stationService.selectStationById(user.getStationId());
            fleetCardQueryForm.setEnterpriseId(station.getEnterpriseId());
        }
        List<FleetCardVo> fleetCardVos = fleetCardService.selectFleetNameList(fleetCardQueryForm);
        return AjaxResult.success(fleetCardVos);
    }

}
